using System;
using System.Collections.Specialized;
using System.IO;
using System.Text;
using System.Web;

namespace WebMonitor.Http.Impl {
    public class HttpRequestAdapter : IHttpRequest {
        private readonly HttpRequest req;

        public HttpRequestAdapter(HttpRequest req) {
            this.req = req;
        }

        public HttpRequestAdapter() {
            req = HttpContext.Current.Request;
        }

        public byte[] BinaryRead(int count) {
            return req.BinaryRead(count);
        }

        public void ValidateInput() {
            req.ValidateInput();
        }

        public int[] MapImageCoordinates(string imageFieldName) {
            return req.MapImageCoordinates(imageFieldName);
        }

        public void SaveAs(string filename, bool includeHeaders) {
            req.SaveAs(filename, includeHeaders);
        }

        public string MapPath(string virtualPath) {
            return req.MapPath(virtualPath);
        }

        public string MapPath(string virtualPath, string baseVirtualDir, bool allowCrossAppMapping) {
            return req.MapPath(virtualPath, baseVirtualDir, allowCrossAppMapping);
        }

        public string HttpMethod {
            get { return req.HttpMethod; }
        }

        public string RequestType {
            get { return req.RequestType; }
            set { req.RequestType = value; }
        }

        public string ContentType {
            get { return req.ContentType; }
            set { req.ContentType = value; }
        }

        public int ContentLength {
            get { return req.ContentLength; }
        }

        public Encoding ContentEncoding {
            get { return req.ContentEncoding; }
            set { req.ContentEncoding = value; }
        }

        public string[] AcceptTypes {
            get { return req.AcceptTypes; }
        }

        public bool IsAuthenticated {
            get { return req.IsAuthenticated; }
        }

        public bool IsSecureConnection {
            get { return req.IsSecureConnection; }
        }

        public string Path {
            get { return req.Path; }
        }

        public string FilePath {
            get { return req.FilePath; }
        }

        public string CurrentExecutionFilePath {
            get { return req.CurrentExecutionFilePath; }
        }

        public string PathInfo {
            get { return req.PathInfo; }
        }

        public string PhysicalPath {
            get { return req.PhysicalPath; }
        }

        public string ApplicationPath {
            get { return req.ApplicationPath; }
        }

        public string PhysicalApplicationPath {
            get { return req.PhysicalApplicationPath; }
        }

        public string UserAgent {
            get { return req.UserAgent; }
            set { }
        }

        public string[] UserLanguages {
            get { return req.UserLanguages; }
        }

        public HttpBrowserCapabilities Browser {
            get { return req.Browser; }
            set { req.Browser = value; }
        }

        public string UserHostName {
            get { return req.UserHostName; }
        }

        public string UserHostAddress {
            get { return req.UserHostAddress; }
        }

        public string RawUrl {
            get { return req.RawUrl; }
        }

        public Uri Url {
            get { return req.Url; }
        }

        public Uri UrlReferrer {
            get {
                try {
                    return req.UrlReferrer;
                } catch (UriFormatException) {
                    return null;
                }
            }
        }

        public NameValueCollection Params {
            get { return req.Params; }
        }

        public string this[string key] {
            get { return req[key]; }
        }

        public NameValueCollection QueryString {
            get { return req.QueryString; }
        }

        public NameValueCollection Form {
            get { return req.Form; }
        }

        public NameValueCollection Headers {
            get { return req.Headers; }
        }

        public NameValueCollection ServerVariables {
            get { return req.ServerVariables; }
            set { }
        }

        public HttpCookieCollection Cookies {
            get { return req.Cookies; }
        }

        public HttpFileCollection Files {
            get { return req.Files; }
        }

        public Stream InputStream {
            get { return req.InputStream; }
        }

        public int TotalBytes {
            get { return req.TotalBytes; }
        }

        public Stream Filter {
            get { return req.Filter; }
            set { req.Filter = value; }
        }

        public HttpClientCertificate ClientCertificate {
            get { return req.ClientCertificate; }
        }
    }
}